<%--
 *  File:    OrgSolutionInitPop.jsp
 *  @Author: Tracy Yuan
 *  Date:    6/12/2003 
 *
 *  Copyright (C) 2000 - 2002 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>

<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page import="com.oval.util.*" %>

<%@ page contentType ="text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>


<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.OrgSolutionInitPop");  
%>

<% //--------------------------------------  variant and initialization --%>
<%
	String strModuleName = "IMG";
	String strTableName = "ovuser";
	String privilegeCode = "Z0803,L801";
	HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
	String strInitFlag = "00000000";
	if (request.getParameter("initflag")!=null)
	  strInitFlag = request.getParameter("initflag");

  
%>

<% //--------------------------------------  include files list --%>

<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<html>
<head>
<title>OrgSolutionInitPop</title>
<script language="JavaScript">
<%if (request.getParameter("pageover")!=null){%>
  opener.refreshWindow();
  window.close();
<%}%>
</script>
<%if (request.getParameter("pageover")==null){%>
<PageFlow:CheckPageFlow pageName="orgsolutioninitpop"/>
<%}%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../js/ScriptLib.js"></script>
<%@ include file="/inc/CheckPassword.inc" %>
<%
  HashMap primaryAdmin=(HashMap)pageContext.getAttribute("orgadmininfo");	 
	if(primaryAdmin == null)
   	primaryAdmin = new HashMap();  
%>
<script language="JavaScript" >
function isAllEnglish(s)	//Is the string s all English? All English:return true.
{
	var i,c;
	for(i=0;i<s.length;i++)
	{
		c=s.charAt(i);
		if((c>="A"&&c<="Z")||(c>="a"&&c<="z")||c=="_"||(c>=0&&c<=9))
		{
			if(c==" ")
				return false;
			continue;
		}
		else
			return false;
	}
	return true;
}
function userEdit(form)
{
    <%if(primaryAdmin == null || primaryAdmin.get("userid") == null ){%>
  	if(!isAllEnglish(form.username.value))
  	{
    	alert("<%= message.getMessageDesc("ILLEGAL_FORMAT",label.getLabelName("L_UserName",false)) %>");
    	return false;
  	}  
  	
  	if((form.username.value.length > 12)||(form.username.value.length < 4))
  	{
    	alert("<%= message.getMessageDesc("LENGTH_MUST_BETWEEN",label.getLabelName("L_UserName",false),"4", "12") %>");
    	return false;
  	}
    <%}%>
    
      if(form.password.value.length == 0)
  	  {
      	alert("<%= message.getMessageDesc("LENGTH_MUST_MORETHAN",label.getLabelName("L_Password",false),"0") %>");
      	return false;
  	  }
  	  
  	  if(form.passwordconfirm.value.length == 0)
  	  {
      	alert("<%= message.getMessageDesc("LENGTH_MUST_MORETHAN",label.getLabelName("L_PasswordConfirm",false),"0") %>");
      	return false;
      }
  	if(form.password.value != form.passwordconfirm.value)
  	{
    	alert("<%= message.getMessageDesc("DIFFERENT_PASSWORD") %>");
    	return false;
  	}  
  	
  	if(!isEmpty(form.email.value) && !emailCheck(form.email.value,true) )
    {
      alert("<%= message.getMessageDesc("ILLEGAL_FORMAT", label.getLabelName("L_Email",false)) %>");
    	return false;
  	} 
  	
  	if(form.password.value == form.username.value)
  	{
    	alert("<%= message.getMessageDesc("VALUE_MUST_NOTEQUAL",label.getLabelName("L_Password",false),label.getLabelName("L_UserName",false)) %>");
    	return false;
  	}  
    if (form.password.value != "" && !checkPassword(form.password.value))
    {
      return false;
    }
    return true;
}

function saveorginit()
{
    var strflag;
    if(!checkForm(document.frm))return;
    if(!confirm('<%= message.getMessageDesc("ARE_YOU_SURE") %>'))
        return;

	  if (frm.chk1.checked)
	  {

	    if(!userEdit(frm))
    	{
      	return;
    	}
	    frm.saveadmin.value ="Y";
	    strflag = '1';
	  }
	  else
	    strflag = document.frm.pos0.value;


	  if (frm.chk2.checked)
	  {
	    frm.saveauthority.value ="Y";
	    strflag = strflag + '1';
	  }
	  else
	    strflag = strflag + document.frm.pos1.value;


	  if (frm.chk3.checked)
	  {
	    frm.saveorgoption.value ="Y";
	    strflag = strflag + '1';
	  }
	  else
	    strflag = strflag + document.frm.pos2.value;

	  strflag = strflag + '1';


      if (frm.chk5.checked)
	  {
	    frm.savesyswh.value ="Y";
	    strflag = strflag + '1';
	  }
	  else
	    strflag = strflag + document.frm.pos5.value;

      strflag = strflag + '000';

    document.frm.initflag.value=strflag;
    document.frm.actionname.value="saveorginit";
    document.frm.target="_self";
    isRunning = true;
    document.frm.submit();
}
function changechk1()
{
  if (frm.chk1.checked)
  {
    document.frm.username.command = "notnull";
    document.frm.password.command = "notnull";
    document.frm.passwordconfirm.command = "notnull";
    document.all.item("tdusername").className = "need";
    document.all.item("tdpassword").className = "need";
    document.all.item("tdpasswordconfirm").className = "need";
  }
  else
  {
    document.frm.username.command = "nullable";
    document.frm.password.command = "nullable";
    document.frm.passwordconfirm.command = "nullable";
    document.all.item("tdusername").className = "td-text";
    document.all.item("tdpassword").className = "td-text";
    document.all.item("tdpasswordconfirm").className = "td-text";
  }
}

</script>
</head>

<body>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
  <tr>
    <td>
      <table border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center" width="100%">
      <form name="frm" method="post" action="../Dispatcher"  target="_self">
          <input type="hidden" name="actionname">
          <input type="hidden" name="pagename" value="orgsolutioninitpop">
          <input type="hidden" name="orgid" value="<%=JspHelper.filterNull( request.getParameter("orgid") )%>">
          <input type="hidden" name="saveadmin" value="">
          <input type="hidden" name="saveauthority" value="">
          <input type="hidden" name="saveorgoption" value="">
          <input type="hidden" name="savesyswh" value="">
          <input type="hidden" name="status" value="41">
          <input type="hidden" name="canupdatepassword" value="Y">
          <input type="hidden" name="isprimaryadmin" value="Y">
          <input type="hidden" name="languagecode" value="<%=JspHelper.filterNull( (String)session.getAttribute("languagecode"))%>">
          <input type="hidden" name="pos0" value="<%=strInitFlag.charAt(0)%>">
          <input type="hidden" name="pos1" value="<%=strInitFlag.charAt(1)%>">
          <input type="hidden" name="pos2" value="<%=strInitFlag.charAt(2)%>">
          <input type="hidden" name="pos5" value="<%=strInitFlag.charAt(5)%>">
          <input type="hidden" name="initflag" value="">
          <custom:hidden name="orgadmininfo" property="userid"/>

          <tr class="deepblue-left" > 
            <td class="title_center" colspan="5">&nbsp;</td>
          </tr>
          <tr class="none"> 
            <td width="27"> 
              <input type="checkbox" name="chk1" class="normalradio" onclick="javascript:changechk1()">
            </td>
            <td colspan="4"><%= label.getLabelName("L_InitAdmin")%></td>
          </tr>
          <tr  class="none"> 
            <td rowspan="2">&nbsp;            
            </td>
            <td id="tdusername" class="td-text" width="90"><%= label.getLabelName("L_UserName") + label.getLabelName("L_Colon") %></td>
            <td width="160">           
            <%if(primaryAdmin == null || primaryAdmin.get("userid") == null ){%>
              <custom:text name="orgadmininfo" property="username" label="L_UserName" module="IMG"/>
            <%}else{%>
              <custom:text name="orgadmininfo" property="username" readonly="true" style="border:none" label="L_UserName" module="IMG"/>
            <%}%>
                           

            </td>
            <td class="td-text" width="90"><%= label.getLabelName("L_Email") + label.getLabelName("L_Colon") %></td>
            <td> 
              <custom:text name="orgadmininfo" property="email" label="L_Email"/>
            </td>
          </tr>
          <tr  class="none"> 
            <td id="tdpassword" class="td-text"><%= label.getLabelName("L_Password") + label.getLabelName("L_Colon") %></td>
            <td> 
              <input type="password" name="password"   value="" label="<%=label.getLabelName("L_Password")%>" size="20"/>
            </td>
            <td id="tdpasswordconfirm" class="td-text"><%= label.getLabelName("L_PasswordConfirm") + label.getLabelName("L_Colon") %></td>
            <td> 
              <input type="password" name="passwordconfirm"   value=""  label="<%=label.getLabelName("L_PasswordConfirm")%>" size="20"/>
            </td>
          </tr>
          <tr class="none"> 
            <td> 
              <input type="checkbox" name="chk2" value="checkbox" class="normalradio">
            </td>
            <td colspan="4"><%= label.getLabelName("L_CopyAuthority") %></td>
          </tr>
          <tr class="none"> 
            <td>
              <input type="checkbox" name="chk3" value="checkbox" class="normalradio">
            </td>
            <td colspan="4"><%= label.getLabelName("L_CopyOrgOption")%></td>
          </tr>
          <tr class="none">
            <td>
              <input type="checkbox" name="chk5" value="checkbox" class="normalradio">
            </td>
            <td colspan="4"><%= label.getLabelName("L_CopySysWareHouse")%></td>
          </tr>
          <tr>
            <td colspan="5">&nbsp; </td>
          </tr>
        </form>
      </table>
      <table width="100%" cellspacing="0" cellpadding="0">
        <tr>
          <td class="summary_top"></td>
        </tr>
        <tr>

          <td class="td_center">
            <a onclick="javascript:saveorginit()"><custom:button type="1" label="L_Finish" imgsrc="finish.gif" border="0" style="width:60"/></a>
            <a onclick="javascript:window.close()"><custom:button type="1" label="L_Cancel" imgsrc="cancel.gif" border="0" style="width:60"/></a>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
